package april.fastjson.namefilter;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.NameFilter;
import com.alibaba.fastjson.serializer.SerializeWriter;

public class HashMapNameFilter {

	public static void main(String[] args) {

		// 可以配置NameFilter，序列化时对Name进行处理。
		NameFilter filter = new NameFilter() {
			@Override
			public String process(Object source, String name, Object value) {
				if (name.equals("id")) {
					return "ID";
				}
				return name;
			}
		};

		SerializeWriter out = new SerializeWriter();
		JSONSerializer serializer = new JSONSerializer(out);
		serializer.getNameFilters().add(filter);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", 0);
		serializer.write(map);

		String text = out.toString();

		System.out.println(text);

	}

}
